package com.luoxiang.socialandroid.dialog

import android.content.Context
import android.widget.ImageView
import android.widget.TextView
import com.luoxiang.socialandroid.R
import com.lxj.xpopup.core.ImageViewerPopupView

class DetailsImageViewerPopup(context: Context) : ImageViewerPopupView(context) {
    private var onReplaceClickListener: (() -> Unit)? = null
    private var onReplaceCoverClickListener: (() -> Unit)? = null
    private var tvReplaceCoverVisibility: Int = VISIBLE

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_details_image_viewer
    }

    override fun initPopupContent() {
        super.initPopupContent()
        findViewById<TextView>(R.id.tv_replace).setOnClickListener {
            dismissWith {
                onReplaceClickListener?.invoke()
            }
        }
        findViewById<TextView>(R.id.tv_replace_cover).setOnClickListener {
            dismissWith {
                onReplaceCoverClickListener?.invoke()
            }
        }
        findViewById<ImageView>(R.id.imageBack).setOnClickListener {
            dismiss()
        }
        findViewById<TextView>(R.id.tv_replace_cover).visibility = tvReplaceCoverVisibility
    }

    fun setOnReplaceClickListener(onReplaceClickListener: () -> Unit){
        this.onReplaceClickListener = onReplaceClickListener
    }

    fun setOnReplaceCoverClickListener(onReplaceClickListener: () -> Unit){
        dismiss()
        this.onReplaceCoverClickListener = onReplaceClickListener
    }

    fun setTvReplaceCoverVisibility(tvReplaceCoverVisibility: Int){
        this.tvReplaceCoverVisibility = tvReplaceCoverVisibility
    }
}